class FoodItem < ActiveRecord::Base
  has_many :ingredients
  has_many :ingredient_types, :through => :ingredients

  def cost
    ingredients.inject(0) do |sum, ingredient|
      sum + ingredient.ingredient_type.cost * ingredient.quantity
    end
  end
  
  def profit
    price - cost
  end

end
